package org.mosquitos.chat;

import java.util.Enumeration;

import net.jxta.discovery.DiscoveryEvent;
import net.jxta.discovery.DiscoveryListener;
import net.jxta.document.Advertisement;
import net.jxta.endpoint.EndpointAddress;
import net.jxta.protocol.DiscoveryResponseMsg;

public class DiscoveryEventListenter implements DiscoveryListener {

	public void discoveryEvent(DiscoveryEvent de) {
        EndpointAddress ea = (EndpointAddress)de.getSource();
        System.out.println("EndpointAddress:"+ea);
        
        Enumeration<Advertisement> srs = de.getSearchResults();
        while(srs.hasMoreElements()){
        	Advertisement a = srs.nextElement();
        	System.out.println("SearchResults Advertisement:"+a);
        	System.out.println("SearchResults AdvertisementType:"+a.getAdvType());
        }
        
        DiscoveryResponseMsg res = de.getResponse();
        
        System.out.println("PeerAdvertisement:"+res.getPeerAdvertisement());
        System.out.println("AdvertisementType:"+res.getAdvertisementType());
        
        Enumeration<Advertisement> as = res.getAdvertisements();
        while(as.hasMoreElements()){
        	Advertisement a = as.nextElement();
        	System.out.println("Advertisement:"+a);
        	System.out.println("AdvertisementType:"+a.getAdvType());
        }
	}
}
